Skip to content

handle duplicate events - #2

Open
rgoers wants to merge 9 commits into
mainfrom
handle-duplicates
Open

handle duplicate events#2
rgoers wants to merge 9 commits into
mainfrom
handle-duplicates

Conversation

@rgoers

@rgoers rgoers commented Sep 2, 2026

Copy link
Copy Markdown
Member

Flume provides guaranteed delivery of events. That means events will be delivered at least once. If an event gets delivered to multiple instances of the sink then the duplicates should fail on a duplicate key, provided the user has specified a key. In these cases we do not want the event being written to be treated as either a success or a failure.

Flapdoodle was also added for embedded MongoDB testing instead of relying on a fake writer.

@rgoers
rgoers requested a review from ppkarwasz September 2, 2026 04:27
@ppkarwasz

Copy link
Copy Markdown
Member

Flapdoodle was also added for embedded MongoDB testing instead of relying on a fake writer.

Honestly I am not a big fan of Flapdoodle. IIRC tests using Flapdoodle were flaky.

Can we use a Docker image instead?

ppkarwasz and others added 8 commits September 2, 2026 19:44
An ordered insertMany() stops at the first duplicate key, which forced a
fallback that re-inserted the rest of the batch one document at a time.
Mark the batch unordered instead: the server attempts every document and
reports each rejected one, with its position in the batch, so a single
round trip both writes everything insertable and yields the exact
duplicate count.

Log the skipped documents broken down by the unique index that rejected
them, with the offending documents themselves at debug level. Drop the
DuplicateKeyException handling: that exception is only thrown by the
legacy com.mongodb.MongoClient.getDB API, which no longer exists in the
5.x driver, so the catch was unreachable.

Assisted-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TeHbzgwRzHuwpUajMksuMD

@ppkarwasz ppkarwasz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the way documents are inserted: they are inserted using an unordered option, which allow the server to try inserting all the documents before failing. The number of duplicates is read from the thrown exception

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants